package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.dao.CmsNoticeSysDao;
import com.bootdo.wx.domain.CmsMaterialDO;
import com.bootdo.wx.domain.CmsNoticeSysDO;
import com.bootdo.wx.domain.CmsSlideDO;
import com.bootdo.wx.service.*;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by HP on 2019/6/17.
 */
@Controller
@RequestMapping("/api/cms")
public class ApiCmsController {

    @Autowired
    private CmsSlideService cmsSlideService;
    @Autowired
    private GoodsSpikeService goodsSpikeService;
    @Autowired
    private GoodsNineService goodsNineService;
    @Autowired
    private GoodsBargainService bargainService;
    @Autowired
    private CmsNoticeSysService cmsNoticeSysService;
    @Autowired
    private GoodsGoodsService goodsGoodsService;
    @Autowired
    private CmsMaterialService cmsMaterialService;

    /**
     * 首页轮播图列表
     * 图片类型：0：首页轮播图，1：支付宝支付二维码
     */
    @PostMapping( "/slide/list")
    @ResponseBody
    public R slideList(@RequestBody Map<String, Object> params){
        if (!params.containsKey("type")|| StringUtils.isBlank(params.get("type").toString())
            ){
            return R.error("参数错误");
        }
        try{
            List<CmsSlideDO> list = cmsSlideService.queryAll(params);
            return R.ok().put("data",list);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }

    /**
     * 首页9.9专区展示
     */
    /*@GetMapping( "/nine")
    @ResponseBody
    public R nine(){
        try{
            Map<String,Object> map = goodsNineService.nine();
            return R.ok().put("data",map);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }*/


    /*
   * 首页砍价专区展示
   * */
    /*@ResponseBody
    @GetMapping("/bargain")
    public R bargain() {
        try{
            Map<String,Object> map = bargainService.bargain();
            return R.ok().put("data", map);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("查询失败");
        }
    }*/

    /*
   * 我的消息（公告）列表
   * */
    @PostMapping( "/noticeSys/list")
    @ResponseBody
    public R noticeSysList(@RequestBody Map<String, Object> params){
        if (!params.containsKey("pageNumber")||!params.containsKey("pageSize")){
            return R.error("参数异常");
        }
        try{
            PageInfo<CmsNoticeSysDO> list = cmsNoticeSysService.queryAll(params);
            return R.ok().put("data",list);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }

    /**
     * 系统公告详情
     */
    @PostMapping( "/noticeSys/info")
    @ResponseBody
    public R noticeSysInfo(@RequestBody Map<String, Object> params){
        if (!params.containsKey("noticeSysId")){
            return R.error("参数异常");
        }
        try{
            String noticeSysId = params.get("noticeSysId").toString();
            CmsNoticeSysDO list = cmsNoticeSysService.get(noticeSysId);
            return R.ok().put("data",list);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }


    /**
     * 首页商品专区展示
     */
    /*@GetMapping( "/nine")
    @ResponseBody
    public R nine(){
        try{
            Map<String,Object> params = new HashMap<String,Object>();
            Map<String,Object> map = goodsGoodsService.getCmsGoods(params);
            return R.ok().put("data",map);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }*/


    /**
     * 官方素材列表
     */
    @PostMapping( "/material/list")
    @ResponseBody
    public R materialList(@RequestBody Map<String, Object> params){
        if (!params.containsKey("pageNumber")||!params.containsKey("pageSize")){
            return R.error("参数异常");
        }
        try{
            PageInfo<CmsMaterialDO> list = cmsMaterialService.queryAll(params);
            return R.ok().put("data",list);
        }catch (Exception e){
            return R.error("服务器网络异常");
        }
    }








}
